/*-------------------<-- Start of Description-->---------------------\ | Close a word document; | |---------------------<-- End of Description-->----------------------| |--------------------------------------------------------------------| |------------<-- Start of Files or Arguments Needed-->---------------| | Arguments: | | wordref: word reference; not necessary, default is "wordsys"; | |-------------<-- End of Files or Arguments Needed-->----------------| |------------------<-- Start of Files Created-->---------------------| |------------------<-- Start of Files Created-->---------------------| | Example: %wordclose; / %wordclose(wordsys); | | Usage: %wordclose(wordref); | \-------------------<-- End of Files Created-->---------------------*/ %macro wordclose/parmbuff; /*--------------------------------------------\ | Copy Right: Duo Zhou; | | Created: 6-4-2001 11:22pm; | | Modified: 1-15-2002 10:50pm; | | Purpose: Close the word document; | \--------------------------------------------*/ %local WORDREF WINREF WINDOW WIN _xwordcloserx_ _xwordcloseoldstr_ _xwordcloseodrnewstr_ fref _xwordclosepos_ _xwordcloselen_ _odrnewstr_ _xodrvarcnt_ _xodrvar_ _xodrx2_ _xodrx3_; %let wordclosestarttime = %sysfunc(datetime()); %let wordclosevaltype=; %let wordclosedlm=; %let list=; %let wordcloselist=; %let wordclose=; %if (%index(%BQUOTE(%trim(%BQUOTE(%left(%BQUOTE(&syspbuff))))), %str(%()) eq 1) and (%index(%BQUOTE(%trim(%BQUOTE(%left(%BQUOTE(%sysfunc(reverse(%BQUOTE(&syspbuff)))))))), %str(%))) eq 1) %then %let syspbuff=%sysfunc(translate(%quote(%substr(%quote(%trim(%quote(%left(%quote(&syspbuff))))), 2, %eval(%length(%trim(%quote(%left(%quote(&syspbuff)))))-2))), %str(%'), %str(%"))); %let win=; %let WORDREF=; %let window=; %let exit=; %let fref=; %let fileref=; %let _xwordcloserx_=%sysfunc(rxparse($(1))); %let _xwordclosepos_=0; %let _xwordcloselen_=0; %let _xwordcloseoldstr_=; %let _xwordcloseodrnewstr_=; %do %while( %sysfunc(rxmatch(&_xwordcloserx_, %quote(&syspbuff))) ); %syscall rxsubstr(_xwordcloserx_, syspbuff, _xwordclosepos_, _xwordcloselen_); %let _xwordcloseoldstr_=%quote(%substr(%quote(&syspbuff), &_xwordclosepos_, &_xwordcloselen_)); %let _xwordcloseodrnewstr_=%quote(%sysfunc(translate(%quote(&_xwordcloseoldstr_), À, %quote(%(), Á, %quote(%)), ´, %quote(,), ®, %quote( )))); %let syspbuff=%sysfunc(tranwrd(%quote(&syspbuff), %quote(&_xwordcloseoldstr_), %quote(&_xwordcloseodrnewstr_))); %let _xwordclosepos_=0; %let _xwordcloselen_=0; %let _xwordcloseoldstr_=; %let _xwordcloseodrnewstr_=; %end; %let _odrnewstr_=&syspbuff; %let _xodrvarcnt_=0; %do %while(%length(%qscan(%nrbquote(&_odrnewstr_), %eval(&_xodrvarcnt_+1), %nrbquote(,)))); %let _xodrvarcnt_=%eval(&_xodrvarcnt_+1); %let _xodrvar_=%nrbquote(%qscan(%nrbquote(&_odrnewstr_), &_xodrvarcnt_, %nrbquote(,))); %let _xodrvar_=%sysfunc(translate(%quote(&_xodrvar_), '(', 'À', ')', 'Á', ',', '´', ' ', '®')); %let _xodrx2_=%trim(%left(%qscan(%quote(&_xodrvar_), 1, %str(=)))); %let _xodrx3_=%substr(%quote(&_xodrvar_), %eval(%index(%quote(&_xodrvar_),%str(=))+1), %eval(%length(&_xodrvar_)-%index(%quote(&_xodrvar_),%str(=)))); %if (not %index(%BQUOTE(%trim(%BQUOTE(%left(%BQUOTE(&_xodrvar_))))), %str(=))) %then %do; %if (%index(%BQUOTE(%trim(%BQUOTE(%left(%BQUOTE(&_xodrx2_))))), %str(%()) eq 1) and (%index(%BQUOTE(%trim(%BQUOTE(%left(%BQUOTE(%sysfunc(reverse(&_xodrx2_))))))), %str(%))) eq 1) %then %let _xodrx3_=%substr(%quote(%trim(%quote(%left(%quote(&_xodrx2_))))), 2, %eval(%length(%trim(%quote(%left(%quote(&_xodrx2_)))))-2)); %if (%quote(&_xodrvarcnt_) = %quote(1)) %then %let exit=&_xodrx3_; %else %if (%quote(&_xodrvarcnt_) = %quote(2)) %then %let fref=&_xodrx3_; %end; %else %if (%index(%BQUOTE(%trim(%BQUOTE(%left(%BQUOTE(&_xodrx3_))))), %str(%()) eq 1) and (%index(%BQUOTE(%trim(%BQUOTE(%left(%BQUOTE(%sysfunc(reverse(&_xodrx3_))))))), %str(%))) eq 1) and (%index(%nrbquote(upcase(%nrbquote(%sysfunc(compress(%nrbquote(&_xodrx2_)))))), WHERE=) le 1) %then %let &_xodrx2_=%substr(%quote(%trim(%quote(%left(%quote(&_xodrx3_))))), 2, %eval(%length(%trim(%quote(%left(%quote(&_xodrx3_)))))-2)); %else %let &_xodrx2_=&_xodrx3_; %end; %if (%quote(&exit) eq) %then %let exit=F; %if (%quote(&fref) eq) and (%quote(&wordref) ne) %then %let fref=&wordref; %else %if (%quote(&fref) eq) and (%quote(&window) ne)%then %let fref=&window; %else %if (%quote(&fref) eq) and (%quote(&fileref) ne)%then %let fref=&fileref; %else %if (%quote(&fref) eq) and (%quote(&win) ne)%then %let fref=&win; %else %if (%quote(&fref) eq) %then %do; Filename wordsys dde 'winword|system' lrecl=1048576; %let fref=wordsys; %put --> Note: No window reference is specified%str(;) Checking the status of the default; %put --> "&fref" to see if it is open.; %end; %if (%quote(&fref) ne) %then %do; %if (%index(%quote(&fref), %quote(\)) or %index(%quote(&fref), %quote(/))) %then %do; FILENAME wordsys dde "winword|&fref" command lrecl=1048576; %let fref=wordsys; %end; %let wsid=%sysfunc(fopen(&fref,s)); %end; %if &wsid %then %do; %let rc=%sysfunc(fclose(&wsid)); data _null_; file &fref; put '[FileClose]'; %if (%index(%quote(%upcase(&exit)), T)) %then %do; put '[FileExit]'; %end; run; %end; %else %do; %put ==> Alert! Incorrect window reference "&fref", or window "&fref" isn%str(%')t open.; %end; %mend wordclose;